<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    

<!DOCTYPE >
<html>
<!-- 后台管理中的新增目标-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/top.css" />
<link rel="stylesheet" href="../../css/other.css" />
<link rel="stylesheet" href="../../css/home.css" />
<link rel="stylesheet" href="../../css/window.css" />
<script src="../../js/jquery.min.js"></script>
<script src="../../js/top_control.js"></script>
<script src="../../js/window.js"></script>
<style>
   div.target_info label.radio_lable{
      width: calc(100% - 5em);
      float:left;
      margin-left:0;
      text-align:left
   }
     div.target_info input[type="radio"]{
        width:2em;
        margin:0.5em;
     }
</style>
<title>智行校园-精准化服务平台</title>
</head>
<body class="background">
  <input  type="hidden" value="新增目标" id="the_goal"/>
<input  type="hidden" value="1323" id="user_id"/>
	<div class="container">
		<div class="targets_left col-2" style="margin-left:0;width:10em"></div>
		<div class="targets_right" style="width:calc(100% - 13.7em);margin-top:0em;padding-bottom:1em">
			 <h3>新增目标</h3><button class="target_submit">确认并发布</button>
			 <div class="target_info">
			     <label style="width:8em"><label class="required">*</label> 目标发布对象 : </label>
			     <div style="width:calc(100% - 12em);margin-left:12em; margin-top: 1em;">
			      <input  type="radio"  name="target_object" checked="checked" value="inside"/><label class="radio_lable" >权限内发布（发送对象：xx班级；xx班级 ）</label><br/><br/>
			      <input  type="radio"  name="target_object" value="outside"/><label class="radio_lable">权限外发布（发送对象：全校师生）</label>
			      <div class="clear"></div>
			     </div>
			   </div>
			 <div class="target_info">
			     <h4>目标基本信息</h4>
			     <label><label class="required">*</label> 目标名称 : </label>
			     <input  placeholder="请输入目标名称"  name="target_name"/>
			     <span class="length_control" data_value="40">0/40</span>
			     <label><label class="required">*</label> 目标简述 : </label><textarea  placeholder="请简述目标" name="target_describe"></textarea>
			 </div>
			 <div class="target_info ">
			     <h4>分解目标</h4>
			      <label><label class="required">*</label>第 1 项 : </label><input  placeholder="请输入不超过60个字符"  /><span class="length_control" data_value="60">0/60</span>
			      <label class="detial_target"> 签到次数 : </label><input placeholder="请填写数字，若不填写则默认为无限次"  />
			      <label class="detial_target"> 相关资料 : </label><input  placeholder="请填写所需的资源或其他条件"  /><span class="length_control" data_value="40">0/40</span>
			 </div>
			 <button class="add_detial_target" >+新增目标分解</button>
			 <button class="target_submit" style="margin-bottom:1em;display:none">确认并发布</button>
		</div>
		     
	</div>
	<script src="../../js/leftcol_control.js"></script>
	<script>
	
	     var user_id="11204050220";
	     var count=0;
	     $(function(){
	    	 input_length_control();
	    	 $('button.add_detial_target').click(function(){
	    		 $('button.target_submit').css('display','block');
	    		 var the_length=$('div.targets_right div.target_info').length-1;
	    		 var str='<div class="target_info" style="padding-top:1em">'+
	    		   '<label > 第 '+the_length+' 项 : </label><input  placeholder="请输入不超过60个字符"  /><span class="length_control" data_value="60">0/60</span>'+
	    		   ' <label class="detial_target"> 签到次数 : </label><input placeholder="请填写数字，若不填写则默认为无限次"  />'+
	    		   '<label class="detial_target"> 相关资料 : </label><input  placeholder="请填写所需的资源或其他条件"  /><span class="length_control" data_value="40">0/40</span></div>';
	    		 $('button.add_detial_target').before(str);
	    		 input_length_control();
	    	 });
	    	 $('button.target_submit').unbind('click').click(function(){
  			   var target_control=$('div.target_info  input:radio[name="target_object"]:checked').val();
  			   var target_name=encodeURI($('div.target_info input[name="target_name"]').val());
		       var target_describe=encodeURI($('div.target_info textarea[name="target_describe"]').val());
		       var detial_target=encodeURI($('div.targets_right div.target_info:eq(1) input:eq(0)').val());
		       var the_length=$('div.targets_right div.target_info').length;
		       var input_count=$('div.targets_right div.target_info:eq(1) input').length;
		       
		       if(target_name==''||target_describe==''||detial_target=='')
		    	   win.alert('系统提示', '有 * 的为必填项，请确保信息完整！！');
		       else{
		    	   win.confirm('系统提示', '发布后的目标将无法进行修，确定发布？');
		    	   $('div.body-panel p.btns button:eq("0")').unbind('click').click(function(){
		    			 var row = new Object();
		    		        var detial=new Array();
		    	            row.name = target_name;
		    	            row.describe = target_describe;
		    	            row.detail = detial;
		  		        for(var i=2;i<the_length;i++){
		  		           var detail_row = new Object();
		  		           var the_nane=encodeURI($('div.targets_right div.target_info:eq('+i+') input:eq(0)').val());
	    		           var the_number=encodeURI($('div.targets_right div.target_info:eq('+i+') input:eq(1)').val());
	    		           var the_resource=encodeURI($('div.targets_right div.target_info:eq('+i+') input:eq(2)').val());
	    		           detail_row.name = the_nane==''?' ':the_nane;
	    		           detail_row.daynum = the_number==''?'-1':the_number;
	    		           detail_row.resource = the_resource==''?' ':the_resource;
	    		           detial.push(detail_row);
		  		         }
		  		        add_targets(user_id,row,target_control);
		  		        win.close();
		  		        count++;
		  		     //   location.href='target_database.jsp';
		    		 });
		      
		       }
	    		
	    	 });
	    	 $('a').click(function(){
	    		 var href=$(this).attr('href');
	    		 if(count==0&&href!='#'){
	    			 win.confirm('系统提示', '离开该编辑界面，数据将无法保留!');
	    			 $('div.body-panel p.btns button:eq("0")').unbind('click').click(function(){
	    				 win.close();
	    				 location.href=href;
	    			 });
	    		 }
	    		 return false;
	    	 });
	    	
	     });
	     function add_targets(user_id,row,target_control){
	    	 var the_target=JSON.stringify(row);
	    	 $.ajax({
	 			url : '/College/target/newAddTarget_teacher',
	 			data:{userid:user_id,targetContent:the_target,teacher_id:user_id,control:target_control},
	 			type : 'post',
	 			success:function(){
	 				 win.alert('系统提示', '目标已添加成功！');
	 				 $('div.target_info input').val('');
	 				 $('div.target_info textarea').val('');
	 			}
	 		});
	     };
	     function input_length_control(){
	    	 $('div.target_info span.length_control').prev().unbind('input propertychange').bind('input propertychange', function() {
				   if($(this).next().attr('data_value')<=$(this).val().length){
					    $(this).next().css('color','red');
					    if($(this).next().attr('data_value')==$(this).val().length)
					       $(this).next().text($(this).val().length+'/'+$(this).next().attr('data_value'));
					    else
					       $(this).next().text('已超过' +($(this).val().length-$(this).next().attr('data_value'))+'个字');
					}
				   else{
					   $(this).next().css('color','black');
					   $(this).next().text($(this).val().length+'/'+$(this).next().attr('data_value'));
				   }
					   
			  });
	     }
	</script>
</body>
</html>